class Solution {
public:
    double myPow(double x, long n) {
        if(n < 0){
            x = 1/x;
            n = -n;
        }
        if(n == 0){
            return 1;
        }

        if(n % 2 == 1){
            return x * myPow(x, n-1);
        }

        return myPow(x*x, n/2);
    }
};